/*
	Trabalho 1 - concorrentes

	PI monte carlo sequencial

	Henrique Teixeira Arroyo	6419241
	Júlio Zanzini Polzato		7288971
	Henry Donabella Leão		5881632
*/

#include <time.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define SAMPLES 1000000000 // total samples to try

// myrandom implementation

const unsigned int A = 1664525, C = 1013904223;

unsigned int myrandom(unsigned int x){
        return x*A+C;
}

// monte carlo main function
int main(){

    double x, y, PI;
    unsigned int i,in_hits, seed;
    
    seed = time(NULL);
    
    // Try samples 
    for(i=0;i<SAMPLES;i++){	
		seed = myrandom(seed);
		x = (double)seed/UINT_MAX;
		seed = myrandom(seed);
		y = (double)seed/UINT_MAX;
        
		if(x*x + y*y < 1.0) // sum circle hits
            		in_hits++;
    }

    PI = (double)4*in_hits/(double)SAMPLES; // compute PI
    printf("PI: %.6f \n", PI);

    return 0;
}
